﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DllDezzerDev;

namespace ConcertFinder
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btn1_Click(object sender, EventArgs e)
        {
            lstbox1.DataSource=LastFmApi.getArtistEvents(txtbox1.Text);
            if (lstbox1.Items.Count != 0)
            {
                lstbox1.Visible = true;
                lbl2.Visible = false;
            }
            else
            {
                    lbl2.ForeColor = System.Drawing.Color.Red;
                    lbl2.Visible = true;
                    lstbox1.Visible = false;
                    webb1.Visible = false;
                    pnlConcert1.Visible = false;
            }
        }

        private void btn3_Click(object sender, EventArgs e)
        {
            lstbox2.DataSource = LastFmApi.getArtistGeo(txtbox2.Text);
           
            if (lstbox2.Items.Count != 0)
            {
                lstbox2.Visible = true;
                lbl4.Visible = false;
                btn4.Visible = true;
            }
            else
            {
                lbl4.ForeColor = System.Drawing.Color.Red;
                lbl4.Visible = true;
                lstbox2.Visible = false;
                btn4.Visible = false;
                pnlConcert2.Visible = false;
                
            }
        }

        

        private void btn4_Click(object sender, EventArgs e)
        {
            Event monEvent2 = new Event();
            monEvent2 = (Event)lstbox2.SelectedItem;

            //Sat, 22 Mar 2014 19:26:01
            //
            /*string substringDeDate = monEvent2.dateDebut;
            string substringDeDateJour = substringDeDate.Substring(5, 2);;
            string substringDeDateMoi = substringDeDate.Substring(8, 3);
            string substringDeDateAnnee = substringDeDate.Substring(12, 4);
            int jour = int.Parse(substringDeDateJour);
            int mois = worldWeatherOnlineApi.convertisseurMoisEnInt(substringDeDateMoi);
            int annee = int.Parse(substringDeDateAnnee);

            
            System.DateTime uneDate = new DateTime(annee, mois, jour);
            lbl3.Text = worldWeatherOnlineApi.getMeteoVille(uneDate, monEvent2.maVenue.localisation.Ville);*/
            lblMeteo.Text = OpenWeatherMap.getMeteoVille(monEvent2.maVenue.localisation.Ville);
            
            
        }

        private void tbc2_Selected(object sender, TabControlEventArgs e)
        {
            if (lstbox1.Items.Count != 0) webb1.Visible = true;
            else webb1.Visible = false;
        }

        private void lstbox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Event monEvent = new Event();
            monEvent = (Event)lstbox1.SelectedItem;
            String urlAGeolocaliser = "https://maps.google.com/?ll=" + monEvent.maVenue.localisation.Latitude + "," + monEvent.maVenue.localisation.Longitude + "&z=15";

            webb1.Navigate(urlAGeolocaliser);
            webb1.Visible = false;
            Event concert = new Event();
            concert=(Event)lstbox1.SelectedItem;
            lblTitle1.Text = concert.title;
            lstBoxArtist1.DataSource = concert.lesArtists;
            lblDate1.Text = concert.dateDebut;
            lblLieu1.Text = concert.maVenue.name;
            lblVille1.Text = concert.maVenue.localisation.Ville;
            pctBox1.ImageLocation = concert.affiche;
            pnlConcert1.Visible = true;
        }

        private void tbc2_Leave(object sender, EventArgs e)
        {
            webb1.Visible = false;
        }

        private void lstbox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            Event concert = new Event();
            concert = (Event)lstbox2.SelectedItem;
            lblTitle2.Text = concert.title;
            lstBoxArtist2.DataSource = concert.lesArtists;
            lblDate2.Text = concert.dateDebut;
            lblLieu2.Text = concert.maVenue.name;
            lblVille2.Text = concert.maVenue.localisation.Ville;
            pctBox2.ImageLocation = concert.affiche;
            pnlConcert2.Visible = true;
            
        }

        

    }
}
